<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link type="text/css" rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
    <script type="text/javascript" src="/webjars/jquery/3.4.1/jquery.js"></script>
    <script type="text/javascript" src="/webjars/vue/2.6.10/dist/vue.js"></script>
    <script type="text/javascript" src="/webjars/axios/0.19.0/dist/axios.js"></script>
    <script type="text/javascript" src="/webjars/bootstrap/3.3.7/js/bootstrap.js"></script>
</head>
<body>
<div id="vuebox">
    <table class="table table-bordered container">
        <thead>
        <tr>
            <th>图书名称</th>
            <th>图书作者</th>
            <th>购买时间</th>
            <th>图书分类</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="item in bookList">
            <td>{{item.bName}}</td>
            <td>{{item.bAuthor}}</td>
            <td>{{item.bTime}}</td>
            <td>
            <p v-if="item.bType==1">计算机/软件</p>
            <p v-if="item.bType==2">小说文摘</p>
            <p v-if="item.bType==3">杂项</p>
            </td>

            <td>
                <button class="btn btn-primary" @click="delBook(item.bId)">删除</button>
            </td>
        </tr>
        </tbody>
    </table>

    <div>
        <a @click="saveBook()">新增图书信息</a>
    </div>

    <!--模态框-->
    <div class="modal" id="mymodal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" type="button" @click="hideModal(),clearForm()" >&times;</button>
                    <div class="modal-title">
                    新增图书信息
                    </div>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label for="bName" class="col-sm-2 control-label">图书名称:</label>
                            <div class="col-sm-10">
                                <input v-model="new_book.bName" id="bName"  type="text" class="form-control" placeholder="请输入图书名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="bAuthor" class="col-sm-2 control-label">图书作者:</label>
                            <div class="col-sm-10">
                                <input v-model="new_book.bAuthor" id="bAuthor"  type="text" class="form-control" placeholder="请输入图书作者"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="bTime" class="col-sm-2 control-label">购买日期:</label>
                            <div class="col-sm-10">
                                <input v-model="new_book.bTime" id="bTime"  type="text" class="form-control" placeholder="请输入购买日期">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="bType" class="col-sm-2 control-label">图书类别:</label>
                            <select name="status" class="form-control" id="bType" v-model="new_book.bType">
                                <option value="0">请选择所属分类</option>
                                <option value="1">计算机/软件</option>
                                <option value="2">小说文摘</option>
                                <option value="3">杂项</option>
                            </select>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" @click="hideModal(),clearForm()">关闭</button>
                    <button class="btn btn-primary" @click="saveModal()">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    var vm=new Vue({
        el:"#vuebox",
        data:{
            bookList:{},
            saveResult:{},
            new_book:{
                bName:'',bAuthor:'',bTime:'',bType:0
            }
        },
        methods: {
            select:function () {
                axios({
                    url:"/selectAll",
                    method:"get",
                    params:{}
                }).then(res=>{
                    this.bookList=res.data

                })
            },
            delBook:function (bId) {
                axios.get("/delBook",{params:{bId:bId}}).then(res=>{
                    this.saveResult=res.data
                    if(this.saveResult.result=="SUCCESS"){
                       alert("删除成功")
                        this.select(1);
                    }else {
                        alert("操作失败请联系管理员")
                    }
                })
            },
            saveBook:function () {
                $('#mymodal').modal('show');
            },
            hideModal:function () {
                $('#mymodal').modal('hide');
            },
            updateproject:function (id) {
                axios({
                    url:"/selectById",
                    method:"get",
                    params:{id:id}
                }).then(res=>{
                    this.new_project=res.data;
                    this.showModal();
                })
            },
            saveModal:function () {
                axios.post("/saveBook",this.new_book).then(res=>{
                    this.saveResult=res.data
                    if(this.saveResult.result=="success"){
                        alert("审核通过!")
                        this.select(1);
                        this.hideModal();
                    }else {
                        alert("审核失败请联系管理员")
                        this.hideModal();
                    }
                })
            }

        },
        mounted(){
            this.select(1);
        }
    })
</script>